<?php
class wages
{
	var $ipsclass;
	var $LIMIT = 25;
	
	function auto_run()
	{
		$wages = array();
		foreach($this->ipsclass->cache['market_wages']['id'] as $wage)
		{
			if(($wage['to_who'] == 'm' && $wage['id_who'] == $this->ipsclass->member['id']) || ($wage['to_who'] == 'g' && $wage['id_who'] == $this->ipsclass->member['mgroup']))
			{
				$wage['how_much'] = $this->ipsclass->numbers->format_currency($wage['how_much']);
				$wage['time'] = $this->ipsclass->get_date($wage['next_payment'],'LONG');
				$wages[] = $wage;
			}
		}
		
		$this->ipsclass->input['st_w'] = intval($this->ipsclass->input['st_w']);
		$this->ipsclass->input['st_t'] = intval($this->ipsclass->input['st_t']);
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_wages_collected','where'=>"(to_who='m' AND id_who=".$this->ipsclass->member['id'].") OR (to_who='g' AND id_who=".$this->ipsclass->member['mgroup'].")"));
		$page_links['wages'] = $this->ipsclass->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																			'PER_PAGE'     => $this->LIMIT,
																			'CUR_ST_VAL'   => $this->ipsclass->input['st_w'],
																			'L_SINGLE'     => $this->ipsclass->compiled_templates['skin_global']->pagination_compile($this->ipsclass->compiled_templates['skin_global']->pagination_make_jump(),"","",$this->ipsclass->compiled_templates['skin_global']->pagination_current_page(1),"","",1,$this->LIMIT,$this->ipsclass->market_class->base_url."CODE=wages",0,'st_w'),
																			'BASE_URL'     => $this->ipsclass->market_class->base_url."CODE=wages&st_t=".$this->ipsclass->input['st_t'],
																			'USE_ST'       => 'st_w'
																	)	);
		
		$collected = array();
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_wages_collected','where'=>"(to_who='m' AND id_who=".$this->ipsclass->member['id'].") OR (to_who='g' AND id_who=".$this->ipsclass->member['mgroup'].")",'order'=>'time_collected DESC','limit'=>array($this->ipsclass->input['st'],$this->LIMIT)));
		$this->ipsclass->DB->exec_query();
		while($collect = $this->ipsclass->DB->fetch_row())
		{
			$collect['time'] = $this->ipsclass->get_date($collect['time_collected'],'LONG');
			$collect['how_much'] = $this->ipsclass->numbers->format_currency($collect['how_much']);
			$collected[] = $collect;
		}
		
		$total = $this->ipsclass->DB->build_and_exec_query(array('select'=>'COUNT(*) as total','from'=>'market_tax_logs','where'=>"member_id=".$this->ipsclass->member['id']." AND amount != 0"));
		$page_links['taxes'] = $this->ipsclass->build_pagelinks(	array(	'TOTAL_POSS'   => $total['total'],
																			'PER_PAGE'     => $this->LIMIT,
																			'CUR_ST_VAL'   => $this->ipsclass->input['st_t'],
																			'L_SINGLE'     => $this->ipsclass->compiled_templates['skin_global']->pagination_compile($this->ipsclass->compiled_templates['skin_global']->pagination_make_jump(),"","",$this->ipsclass->compiled_templates['skin_global']->pagination_current_page(1),"","",1,$this->LIMIT,$this->ipsclass->market_class->base_url."CODE=wages",0,'st_t'),
																			'BASE_URL'     => $this->ipsclass->market_class->base_url."CODE=wages&st_w=".$this->ipsclass->input['st_w'],
																			'USE_ST'       => 'st_t'
																	)	);
		
		$taxes = array();
		$this->ipsclass->DB->build_query(array('select'=>'*','from'=>'market_tax_logs','where'=>"member_id=".$this->ipsclass->member['id']." AND amount != 0",'order'=>'l_time DESC','limit'=>array($this->ipsclass->input['st'],$this->LIMIT)));
		$this->ipsclass->DB->exec_query();
		while($log = $this->ipsclass->DB->fetch_row())
		{
			$log['time'] = $this->ipsclass->get_date($log['l_time'],'LONG');
			$log['how_much'] = $this->ipsclass->numbers->format_currency($log['amount']);
			$taxes[] = $log;
		}
		
		$this->ipsclass->nav[] = "<a href='".$this->ipsclass->market_class->base_url."CODE=wages'>".$this->ipsclass->lang['regular_wages_taxes']."</a>";
		
		$this->ipsclass->output = $this->ipsclass->compiled_templates['skin_market']->wage_page($wages,$collected,$taxes,$page_links);
	}
}
?>